package com.lalilu.lmedia.entity

import android.net.Uri

data class LAlbum(
    override val id: String,
    override val name: String,
    override val songs: List<LSong>,
    val artistName: String? = null
) : MusicParent() {
    override fun getMatchSource(): String = "$name ${artistName ?: ""}"

    val coverUri: Uri?
        get() = songs.first { it.albumCoverUri != null }.albumCoverUri
}

fun List<LAlbum>.merge(): List<LAlbum> {
    return groupBy { it.name }.values.map { list ->
        list[0].copy(songs = list.flatMap { it.songs })
    }
}

fun List<LAlbum>.link() = onEach { album ->
    album.songs.forEach { it.link(album) }
}